<template>
    <div>
        <Modal v-model="data.isShow" :mask-closable="false" width="360">
			<p slot="header" class="header-view">换卡</p>
			<div class="main-view">
                <Form ref="formInline" :model="data.data" :rules="ruleInline" :label-width="80">
                    <FormItem label="密码" prop="password">
                        <Input type="password" v-model="data.data.password" placeholder="请输入密码" class="input"></Input>
                    </FormItem>
                    <FormItem label="新卡号" prop="cardNo">
                        <Input type="text" v-model="data.data.cardNo" placeholder="请输入新卡号" class="input"></Input>
                    </FormItem>
                    <FormItem label="新卡类型" prop="cardCategoryId">
                        <RadioGroup v-model="data.data.cardCategoryId">
                            <Radio 
                                :label="item.cId" 
                                v-for="(item, index) in memberTypeList"
                                :key="index">
                                {{item.name}}
                            </Radio>
                        </RadioGroup>
                    </FormItem>
                </Form>
			</div>
            <div slot="footer">
				<Button type="primary" :isLoading="data.isLoading" @click="clickSubmit">确定</Button>
				<Button @click="data.isShow = false">取消</Button>
			</div>
		</Modal>
    </div>
</template>

<script>
var phoneReg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/; 
import memberService from '@/network/service/memberService.js'

    export default {
        props: ['data'],
        data() {
            return {
                memberTypeList: [],
                ruleInline: {
                    password: [
                        { required: true, message: '请输入密码', trigger: 'blur' }
                    ],
                    cardNo: [
                        { required: true, message: '请输入新卡号', trigger: 'blur' }
                    ],
                    cardCategoryId: [
                        { required: true, message: '请选择新卡类型', trigger: 'change',type: 'number' }
                    ]
                }
            }
        },
        mounted() {
            this.getAddCardType();
        },
        methods: {
            getAddCardType () {
                memberService.addCardType('6').then(res => {
                    let result = res.data;
                    let code = result.rescode;
                    let resmsg = result.msg;
                    if (code == 100) {
                        this.memberTypeList = result.data;
                    } else {
                        this.$Message.error(resmsg)
                    }
                }, error => {
                    this.$Message.error('服务器异常，请稍后再试');
                })
            },
            clickSubmit() {
                this.$refs['formInline'].validate((valid) => {
                    if (valid) {
                        this.$emit('on-submit', this.data);
                    } else {
                        this.$Message.error('表单验证失败!');
                    }
                })
            }
        }
    }
</script>

<style scoped lang="less">
.header-view {
    text-align: center;
}
.main-view {
    text-align: center;
    .input {
        border: .01rem solid #D5CED2;
        border-radius: 5px;
        color: #433e41;
    }
}
</style>